Skip to content

feat(io): add duplex forwarding for BufReader/BufWriter and optimize repeat::read_vectored - #695

Merged
Berrysoft merged 2 commits into
compio-rs:masterfrom
Aalivexy:feat/buf-duplex-forwarding
Feb 16, 2026
Merged

Berrysoft merged 2 commits into
compio-rs:masterfrom
Aalivexy:feat/buf-duplex-forwarding

Conversation

@Aalivexy

@Aalivexy Aalivexy commented Feb 16, 2026 •

Copy link
Copy Markdown
Contributor

It is worth noting that the current implementation retains the read buffer when writing with BufReader, and does not implicitly flush the write buffer when reading with BufWriter. These behaviors are aligned with the tokio design.

Closes #691

Copilot AI review requested due to automatic review settings February 16, 2026 02:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds duplex forwarding capabilities to BufReader and BufWriter, allowing them to forward complementary I/O operations to their inner types when those types support them. This addresses issue #691 by enabling BufReader to implement AsyncWrite (when the inner type supports it) and BufWriter to implement AsyncRead/AsyncBufRead (when the inner type supports them). The implementation follows tokio's design philosophy: BufReader retains its read buffer when writing, and BufWriter does not implicitly flush when reading. Additionally, this PR optimizes repeat::read_vectored with a dedicated implementation.

Changes:

  • Added AsyncWrite trait implementation for BufReader<R> when R: AsyncRead + AsyncWrite
  • Added AsyncRead and AsyncBufRead trait implementations for BufWriter<W> when the inner type supports them
  • Implemented optimized read_vectored for Repeat to efficiently fill vectored buffers

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
compio-io/src/read/buf.rs Added AsyncWrite trait forwarding for BufReader when inner type supports it
compio-io/src/write/buf.rs Added AsyncRead and AsyncBufRead trait forwarding for BufWriter when inner type supports them
compio-io/src/util/repeat.rs Added optimized read_vectored implementation for Repeat type
compio-io/tests/io.rs Added comprehensive tests for duplex forwarding behavior and repeat_read_vectored
compio-io/CHANGELOG.md Documented new trait implementations in unreleased section

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread compio-io/CHANGELOG.md Resolved
@George-Miao George-Miao added enhancement New feature or request package: io Related to compio-io performance Performance related (regression/optimization) labels Feb 16, 2026
Berrysoft
Berrysoft previously approved these changes Feb 16, 2026

@Berrysoft Berrysoft left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Feel free to determine whether to edit the change log. Actually it's generated by release-plz.

EDIT: @George-Miao requires removing them:)

Comment thread compio-io/CHANGELOG.md Resolved
@Berrysoft
Berrysoft self-requested a review February 16, 2026 02:53

@George-Miao George-Miao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Berrysoft
Berrysoft merged commit 1831119 into compio-rs:master Feb 16, 2026
53 of 54 checks passed
@github-actions github-actions Bot mentioned this pull request Feb 16, 2026
This was referenced Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request package: io Related to compio-io performance Performance related (regression/optimization)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

impl AsyncWrite for BufReader

4 participants